package UCM;

import Source.EditFlight;
import Views.ViewEditFlight;

/**
 *
 * @author Joshua King
 */
public class UCEditFlight implements UCController {
    private ViewEditFlight view;
    private EditFlight model = new EditFlight();
            
    public UCEditFlight(ViewEditFlight view) {
        this.view = view;
        view.loadTo(model);
    }

    /**
* Precondition: Logged on as manager on view flights UI.

   1. Manager changes details and clicks the change button.
   2. System loads data to the model.
   3. System checks validity of data.
   4. System commits data.
   5. System refreshes the edit flight UI indicating success. 

Postcondition: A flights information is updated.

Unsuccessful Outcome:

    * 3a) The details entered by the manager are inappropriate.
         1. System refreshes the UI and explains errors to the manager. 
    * 4a) System can't commit data.
         1. System updates the UI informing the manager that the service is currently unavailable. 
    * 4b) System receives notice that an error has occurred.
         1. System updates the UI informing the manager that there was an internal error. 
     */
    public void run() {
        //2. System loads data to the model.
        view.loadData();
        //3. System checks validity of data.
        if (model.checkValidity()) {
           
        if (model.commitData()) {
                //5. System refreshes the edit airport UI indicating success.
                view.refresh();
            } else {
//                4a) System can't commit data.
//                1. System updates the UI informing the manager that the service is currently unavailable. 
//                4b) System receives notice that an error has occurred.
//                1. System updates the UI informing the manager that there was an internal error.
                view.updateFailure();
            }
        } else {
//          3a) The details entered by the manager are inappropriate.
//          1. System refreshes the UI and explains errors to the manager. 
            view.updateFailure();
        }
    }

}
